<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2022/7/5
  Time: 15:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>搜索结果</title>
    <link href="css/BootStrap.css" rel="stylesheet">
    <script src="js/BootStrap.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/styles.css" rel="stylesheet">
    <!-- 引入 Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/BootStrap.js"></script>
    <style>
        .room{
            width: 310px;
            margin-left: 10px;
        }
        .fl_left{
            float: left;
        }
        .bed{
            width: 120px;
            margin-left: 30px;
        }
        .price{
            width: 120px;
            margin-left: 34px;
            text-align: right;
        }
        .page-center{
            text-align: center;
        }

    </style>
</head>
<jsp:useBean id="dataBean" class="bean.Record_Bean" scope="session"/>
<jsp:setProperty name="dataBean" property="pageSize" param="pageSize"/>
<jsp:setProperty name="dataBean" property="currentPage" param="currentPage"/>
<%!String s;
ArrayList<String>hotelID;
ArrayList<String>hotelName;
ArrayList<String>hotelAddress;

%>
<%
s=request.getParameter("currentPage");
System.out.println("currentPage"+s);
%>
<%--获取currentPage和pageSize--%>
<header id="header">
    <nav id="main-nav" class="navbar navbar-default navbar-fixed-top" role="banner">
        <div class="navbar-header">
            <a class="navbar-brand" ><img src="image/图标.png" alt="logo"></a>
        </div>
        <div class="collapse navbar-collapse navbar-right">
            <ul class="nav navbar-nav">
                <li class="scroll active"><a href="login.jsp">登录</a></li>
                <li class="scroll"><a href="register.jsp">注册</a></li>
                <li class="scroll"><a href="person.jsp">个人空间</a></li>
                <li class="scroll"><a href="#">联系客服</a></li>
            </ul>
        </div>
    </nav>
</header>
<br>
<br>
<br>
<br>
<body>
    <div class="background" id="background">
        <br>
        <br>
        <div class="container">
            <div class="container-fluid">
                <%
                    hotelName=dataBean.getHotelName();
                    hotelAddress=dataBean.getHotelAddress();
                    hotelID=dataBean.getHotelID();
                    if (hotelName.size()==0){
                        out.print("很抱歉没有找到记录");
                    }

                    int totalRecord=hotelName.size();
                    int pageSize=dataBean.getPageSize();//每页显示的记录数
                    int totalPages=dataBean.getTotalPages();
                    if (totalRecord==0)
                        out.print("很抱歉未查询到相关地点");
                    if (totalRecord%pageSize==0)
                        totalPages=totalRecord/pageSize;//总页数
                    else
                        totalPages=totalRecord/pageSize+1;
                    dataBean.setPageSize(pageSize);
                    dataBean.setTotalPages(totalPages);
                    if (totalPages>=1) {
                        if (dataBean.getCurrentPage() < 1)
                            dataBean.setCurrentPage(1);
                        if (dataBean.getCurrentPage() > dataBean.getTotalPages())
                            dataBean.setCurrentPage(1);
                        int index = (dataBean.getCurrentPage() - 1) * pageSize;

                        for (int i = index; i < pageSize + index; i++) {
                            if (i == totalRecord)
                                break;
                            out.print("<div class=\"row\">" +
                                    "<div class=\"img_box\" tabindex=\"0\">" +
                                    "<span class=\"room fl_left\">" +
                                    "<img alt=\"物理酒店图片\" src=\"https://himg5.qunarzz.com/imgs/202109/11/C.RXfq77QLV33kx4ysQi240.jpg\" tabindex=\"0\"></span>");

                            String nameResult="<span class=\"bed fl_left\">" + hotelName.get(i) + "</span>";
                            out.print(nameResult);
                            String addressResult="<span class=\"price fl_left\">"+hotelAddress.get(i)+"</span>";
                            out.print(addressResult);
                            String detail="<span class=\"price fl_left\"><a href='QueryServlet?hotelName=\""+hotelName.get(i)+"\"&hotelAddress=\""+hotelAddress.get(i)+"\"&hotelID=\""+hotelID.get(i)+"\"&from="+"result"+ "'>进入酒店</a></span>";
                            out.print(detail);
                            out.print("</div>");
                            out.print("</div>");
                            out.print("<hr>");
                        }
                    }
                %>
            </div>
        </div>
    </div>

    <!--分页功能-->
    <div class="container">
        <div class="container-fluid">
            <div class="page-center">
                <nav aria-label="Page navigation example">
                    <ul class="pagination">
                        <li class="page-item disabled">
                            <a class="page-link" href="result.jsp?currentPage=1">首页</a>
                        </li>
                        <li class="page-item"><a class="page-link"  href="result.jsp?currentPage=<%=dataBean.getCurrentPage()-1%>">
                            上一页</a></li>
                        <li class="page-item"><a class="page-link"  href="result.jsp?currentPage=<%=dataBean.getCurrentPage()%>"><%=dataBean.getCurrentPage()%></a></li>
                        <li class="page-item"><a class="page-link"  href="result.jsp?currentPage=<%=dataBean.getCurrentPage()+1%>"><%=dataBean.getCurrentPage()+1%></a></li>
                        <li class="page-item">
                            <a class="page-link"  href="result.jsp?currentPage=<%=dataBean.getCurrentPage()+1%>">下一页</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</body>
</html>